<template>
  <div>
    <v-header>
      <v-back></v-back>
    </v-header>

    <!-- <div class="main">
        <p>x</p>
        <p>
            <span>zs</span>
            <span>111</span>
            <span>默认</span>
        </p>
        <p>
            <span>辽宁省</span>
            <span>点击</span>
        </p>
    </div> -->
    <div >
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        :disabled-list="disabledList"
        disabled-text="暂无有效地址"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
      />
    </div>
  </div>
</template>

<script>
import {getaddresslist} from '@/request/api.js'
export default {
  data() {
    return {
      chosenAddressId: "1",
      list: [
        {
          id: "1",
          name: "张三",
          tel: "13000000000",
          address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
          isDefault: true,
        },
        {
          id: "2",
          name: "李四",
          tel: "1310000000",
          address: "浙江省杭州市拱墅区莫干山路 50 号",
        },
      ],
      disabledList: [
        /* {
          id: "3",
          name: "王五",
          tel: "1320000000",
          address: "浙江省杭州市滨江区江南大道 15 号",
        }, */
      ],
      user:{},
    };
  },
  methods: {
    onAdd() {
      this.$router.push("/addressNewAdd");
    },
    onEdit(){
console.log(this.chosenAddressId);
    }
  },
  async created(){
    this.user = JSON.parse(localStorage.user);

    let obj = {
      uid : this.user.uid
    }
    let getaddresslistRes = await getaddresslist(obj)
    console.log(getaddresslistRes,"getaddresslist");

    for(let item of getaddresslistRes.data.list){
      this.$set( item,'name',item.username )
      this.$set( item,'tel',item.userphone )
      this.$set( item,'address',item.location+item.useraddress )
    }
    getaddresslistRes.data.list.forEach((v,i,self)=>{
      if(v.status){
        this.chosenAddressId = i+1+''
        console.log(i);
        console.log(this.chosenAddressId);
        return
      }
      return 0;
    })
    // console.log(array,'1111111');
    this.list = getaddresslistRes.data.list
  }
};
</script>

<style>
</style>